home *** CD-ROM | disk | FTP | other *** search
- // Application.c
- // by Stefan C. Sinclair Copyright © 1995-1996 All rights reserved.
-
- #include "Application.h"
-
- Boolean gIsRunning, gQT, gSoundOff, gSoundMax, gSoundMegaMax, gSpeech;
- Boolean gSecretCode[kNumSecretCodes];
- SndChannelPtr gSoundChanP1, gSoundChanP2, gSoundChanGame;
- PixPatHandle gLifePixPatH;
- CWindowPtr gWindowP;
- short gFrameAdvanceTime, gPlayer1Controller, gPlayer2Controller, gFileLoaded[3];
- SpriteFileRec gPlayer1File, gPlayer2File;
- CombatZoneFileRec gCombatZoneFile;
-
- void main(void)
- {
- OSErr err = noErr;
- Boolean appOK = FALSE;
-
- if (Initialize())
- {
- OpeningSplash();
- SetGlobals();
- if(CheckSystem())
- {
- err = InstallAppleEventHandlers();
- if (err != noErr)
- ErrorAlert(err, kUnknownErrorStringIndex);
- }
- else
- ExitToShell();
-
- CreateMenuBar();
- appOK = EnterApplication();
- if (appOK)
- {
- GetStefanStuff();
- EventLoop();
- }
- }
- ExitApplication();
- }
-
- void OpeningSplash(void)
- {
- short ok;
- Handle soundH;
- SndChannelPtr musicChan;
-
- ErrorSound(nil);
- // Get the music
- soundH = Get1Resource('snd ', kOpeningSoundResID);
- if(soundH == NULL)
- CantFindResource();
- MoveHHi(soundH);
- HLock(soundH);
- InitSoundChannel(&musicChan);
- PlaySound(soundH, musicChan);
-
- ok = Alert(kIntroSplashAlertID, NULL);
-
- // Turn off the music
- StopPlayingSound(musicChan);
- HUnlock(soundH);
- ReleaseResource(soundH);
- KillSoundChannel(&musicChan);
- }
-
-
- void SetGlobals(void)
- {
- short i;
-
- gIsRunning = TRUE, gQT = FALSE, gSpeech = FALSE;
- gSoundOff = FALSE, gSoundMax = FALSE, gSoundMegaMax = FALSE;
- gFileLoaded[0] = gFileLoaded[1] = gFileLoaded[2] = FALSE;
- gFrameAdvanceTime = 9; // 50% of full speed
- gPlayer1Controller = kPlayer1Sprite;
- //gPlayer2Controller = kComputer2Sprite;
- gPlayer2Controller = kPlayer2Sprite;
- SetToZero((Ptr)(&gPlayer1File), sizeof(SpriteFileRec));
- SetToZero((Ptr)(&gPlayer2File), sizeof(SpriteFileRec));
- SetToZero((Ptr)(&gCombatZoneFile), sizeof(SpriteFileRec));
- for(i=0; i<kNumSecretCodes; i++)
- gSecretCode[i] = FALSE;
- }
-
- void GetStefanStuff(void)
- {
- gLifePixPatH = GetPixPat(kLifePixPatID);
- if (gLifePixPatH == NULL)
- CantFindResource();
- DetachResource((Handle)gLifePixPatH);
-
- // Randomize the computer's clock for later useage...
- GetDateTime((unsigned long *)&qd.randSeed);
- }
-
- void InitSoundChannel(SndChannelPtr *gChan)
- {
- OSErr myErr;
- SndChannelPtr sChan;
-
- sChan = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
- if(!sChan)
- DoError(kGeneralMemoryError, TRUE);
- sChan->qLength = stdQLength; // 128 sound commands
- myErr = SndNewChannel(&sChan, sampledSynth, initMono+initNoInterp, nil);
- if(myErr != noErr)
- DoError(kCouldNotCreateASoundChannel, TRUE);
-
- *gChan = sChan;
- }
-
- void KillSoundChannel(SndChannelPtr *gChan)
- {
- OSErr myErr;
- SndCommand command;
- SndChannelPtr sChan = *gChan;
-
- if(sChan == NULL)
- return;
-
- while(SndChannelBusy(sChan))
- {
- command.cmd = flushCmd;
- command.param1 = command.param2 = 0;
- myErr = SndDoImmediate( sChan, &command);
- if(myErr)
- DoError(kCouldNotFlushSoundChannel, TRUE);
- command.cmd = quietCmd;
- command.param1 = command.param2 = 0;
- myErr = SndDoImmediate( sChan, &command);
- if(myErr)
- DoError(kCouldNotQuietSoundChannel, TRUE);
- }
-
- myErr = SndDisposeChannel(sChan, TRUE);
- if(myErr != noErr)
- DoError(kBadSoundChannel, TRUE);
- DisposePtr((Ptr)sChan);
- myErr = MemError();
- if(myErr != noErr)
- DoError(kGeneralMemoryError, TRUE);
- *gChan = NULL;
-
- }
-
- void SetToZero(void *theAddr, Size numBytes)
- {
- Ptr aPtr;
- Size i;
-
- aPtr = (Ptr)theAddr;
- for(i=0; i<numBytes; i++)
- aPtr[i] = 0;
- }
-
- void Ceremonies(void)
- {
- Handle textH, soundH;
- short textID = 128; //• rsrc ID# for text used.
- short styleID = 128; //• rsrc ID# for styl used.
- long systemTime, delayTime=6;
- StScrpHandle styleHdl;
- TEHandle textHand;
- Rect txtRect;
- Boolean haveEvent;
- EventRecord event;
- SndChannelPtr musicChan;
- short scrollSpeed;
-
- //• Uncomment this line for a beta test release.
- //DoMessage(kBetaNotice);
-
- // Some text to display
- //• Create styled TERecord.
- txtRect = gWindowP->portRect;
- //InsetRect(&txtRect, 5, 1);
- textHand = TEStylNew(&txtRect, &txtRect);
- TESetJust (1, textHand);
- //• Read the TEXT resource.
- textH = GetResource('TEXT', textID);
- HLock(textH); //• Lock handle.
- //• Get the style handle.
- styleHdl = (StScrpHandle)(Get1Resource('styl', styleID));
- TEStylInsert(*textH, SizeResource(textH), styleHdl, textHand); //• move text into text record.
- HUnlock(textH); //• Unlock handle.
- // Set the pens
- ForeColor(whiteColor);
- BackColor(blackColor);
-
- TEUpdate(&txtRect, textHand); //• Draw text in viewRect.
- //InsetRect(&txtRect, -5, -1);
- // Get the music
- soundH = Get1Resource('snd ', kTextSoundResID);
- if(soundH == NULL)
- CantFindResource();
- MoveHHi(soundH);
- HLock(soundH);
- InitSoundChannel(&musicChan);
-
- while(!Button())
- {
- if(isPressed(keyOption)) // if option is down, then go fast
- {
- scrollSpeed = 2;
- }
- else
- {
- Delay(delayTime, &systemTime); // wait a bit
- scrollSpeed = 1;
- }
- if(isPressed(keyShift))
- scrollSpeed *= 1; // scroll down, instead of up
- else
- scrollSpeed *= -1; // scroll up
- TEPinScroll(0, scrollSpeed, textHand);
- LoopSound(soundH, musicChan);
- haveEvent = WaitNextEvent(everyEvent, &event, 0, NULL); // Let menu clock update!
- //••••••••••• This would be a REALLY GOOD place to hide a startup code!!!!!!!!!!!!!!!!!
- }
- // when done
- TEDispose(textHand);
- // Turn off the music
- StopPlayingSound(musicChan);
- HUnlock(soundH);
- ReleaseResource(soundH);
- KillSoundChannel(&musicChan);
-
- // Reset the pens
- ForeColor(blackColor);
- BackColor(whiteColor);
- RefreshMainWindow();
- }
-
- Boolean Initialize(void)
- {
- OSErr err = noErr;
- EventRecord tempEvent;
-
- if (err == noErr)
- {
- MaxApplZone();
- MoreMasters();
- err = MemError();
- }
- if (err == noErr)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- FlushEvents(everyEvent, 0);
- }
- else
- ExitToShell();
-
- return err == noErr;
- }
-
- Boolean CheckSystem(void)
- {
- OSErr err;
- Boolean isSystemGood = true;
- long gestaltResult, longVersion;
- NumVersion *sndMgrVersion;
-
- // Check for Time Mgr (System 7.0 or higher)
- err = Gestalt(gestaltTimeMgrVersion, &gestaltResult);
- isSystemGood = (err == noErr) && (gestaltResult >= gestaltStandardTimeMgr);
- if (!isSystemGood)
- CantRunOnThisMachine(kNeedSystem7, TRUE);
-
- // Check forColor QuickDraw
- if(!SWHasColorQuickDraw())
- CantRunOnThisMachine(kNeedColorQuickDraw, TRUE);
- else
- isSystemGood = TRUE;
-
- // Check for Sound Mgr 3.0 or better
- isSystemGood = TrapAvail(_SoundDispatch);
- if (!isSystemGood)
- CantRunOnThisMachine(kNeedSoundMgr3, TRUE);
- else
- {
- longVersion = SndSoundManagerVersion();
- sndMgrVersion = (NumVersion *)&longVersion;
- if(sndMgrVersion->majorRev >= 3)
- isSystemGood = TRUE;
- else
- CantRunOnThisMachine(kNeedSoundMgr3, TRUE);
- }
- // Check for QuickTime™
- err = Gestalt( gestaltQuickTime, &gestaltResult );
- if (err != noErr)
- {
- gQT = FALSE;
- DoError(kNoQuickTimeInstalled, FALSE);
- }
- else
- {
- err = EnterMovies();
- if (err != noErr)
- CantRunOnThisMachine(kNeedQuickTime, TRUE);
- else
- {
- isSystemGood = TRUE;
- gQT = TRUE;
- RDQTConflictCheck(); // If QT present, check for RamDoubler conflict.
- }
- }
-
- // Check for Speech Manager
- if(Gestalt( gestaltSpeechAttr, &gestaltResult ) == noErr)
- {
- if(BitTst(&gestaltResult, 31 - gestaltSpeechMgrPresent))
- {
- isSystemGood = TRUE; // Good anyway; just checking for fun.
- gSpeech = TRUE;
- }
- else
- gSpeech = FALSE;
- }
-
- // Check for MacsBug
- if(MacsBugInstalled())
- isSystemGood = TRUE; // Good anyway; just checking for fun.
-
- return isSystemGood;
- }
-
-
- #ifndef NewAEEventHandlerProc
- #define NewAEEventHandlerProc(x) ((EventHandlerProcPtr)x)
- #endif
-
- OSErr InstallAppleEventHandlers(void)
- {
- OSErr err = noErr;
-
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(HandleOpenApp), 0, false);
- if (err == noErr)
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(HandleOpenDoc), 0, false);
- if (err == noErr)
- err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(HandlePrintDoc), 0, false);
- if (err == noErr)
- err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(HandleQuit), 0, false);
- return err;
- }
-
-
- void CreateMenuBar(void)
- {
- Handle menuBarH;
- MenuHandle specialMenu;
- int notANormalMenu = -1;
-
- menuBarH = GetNewMBar(kMenuBarResID);
-
- if (menuBarH != NULL)
- {
- SetMenuBar(menuBarH);
- AddResMenu(GetMHandle(kAppleMenuID), 'DRVR');
-
- // Add sub-menus
- specialMenu = GetMenu(kP1ControlMenuID);
- InsertMenu(specialMenu, notANormalMenu);
- specialMenu = GetMenu(kP2ControlMenuID);
- InsertMenu(specialMenu, notANormalMenu);
- specialMenu = GetMenu(kAdjustSpeedMenuID);
- InsertMenu(specialMenu, notANormalMenu);
-
- DrawMenuBar();
- }
- else
- CantFindResource();
- }
-
- Boolean EnterApplication(void)
- {
- OSErr err;
- Rect windRect;
- short mBarHeight;
-
- err = SWEnterSpriteWorld();
-
- if (err == noErr)
- {
- mBarHeight = LMGetMBarHeight();
- windRect.top = mBarHeight + mBarHeight; // so window title bar can be seen!
- // Check for big enough monitor
- if((qd.screenBits.bounds.right<640)||(qd.screenBits.bounds.bottom<480))
- CantRunOnThisMachine(kNeed14inchMonitor, FALSE);
- windRect.left = 0;
- windRect.right = 640;
- windRect.bottom = 480;
- gWindowP = (CWindowPtr)GetNewCWindow(kWindowResID, nil, (WindowPtr)(-1L));
- if (gWindowP == NULL)
- CantFindResource();
- SetPort((GrafPtr)gWindowP);
- }
- if (err == noErr)
- {
- ShowWindow((WindowPtr)gWindowP);
- InvalRect(&gWindowP->portRect);
- }
- if (err != noErr)
- ErrorAlert(err, kUnknownErrorStringIndex);
- return err == noErr;
- }
-
-
- void ExitApplication(void)
- {
- Handle gameOver;
- OSErr err;
- Rect overRect;
- PicHandle overPict;
-
- overRect.top = overRect.left = 0;
- overRect.bottom = 78;
- overRect.right = 253;
- MyCenterRect(&overRect, &gWindowP->portRect);
-
- FillRect(&gWindowP->portRect, &qd.black);
- overPict = GetPicture(kGameOverManPictID);
- if(overPict == nil)
- DoError(kResError, TRUE);
- HLock((Handle)overPict);
- DrawPicture(overPict, &overRect);
- HUnlock((Handle)overPict);
- ReleaseResource((Handle)overPict);
-
- if(!isPressed(keySpace))
- {
- gameOver = Get1Resource('snd ', kGameOverManSndID);
- if(gameOver == NULL)
- ExitToShell();
- HLock(gameOver);
- err = SndPlay( nil, (SndListHandle)gameOver, FALSE);
- HUnlock(gameOver);
- ReleaseResource(gameOver);
- }
-
- ExitToShell();
- }
-
-
- void EventLoop(void)
- {
- Boolean haveEvent;
- EventRecord event;
-
- while (gIsRunning)
- {
- haveEvent = WaitNextEvent(everyEvent, &event, kForeGroundSleepTime, NULL);
-
- if (haveEvent)
- {
- DispatchEvent(&event);
- }
- else
- {
- HandleNullEvent();
- }
- }
- }
-
-
- void DispatchEvent(EventRecord* event)
- {
- switch(event->what)
- {
- case mouseDown:
- HandleMouseEvent(event);
- break;
- case mouseUp:
- break;
- case keyUp:
- break;
- case keyDown:
- case autoKey:
- HandleKeyEvent((char)(event->message & charCodeMask), event->modifiers);
- break;
- case updateEvt:
- HandleUpdateEvent((WindowPtr)event->message);
- break;
- case diskEvt:
- break;
- case activateEvt:
- break;
- case networkEvt:
- break;
- case driverEvt:
- break;
- case app1Evt:
- break;
- case app2Evt:
- break;
- case app3Evt:
- break;
- case osEvt:
- break;
- case kHighLevelEvent:
- AEProcessAppleEvent(event);
- break;
- default:
- break;
- }
- }
-
-
- void HandleMouseEvent(EventRecord* event)
- {
- WindowPtr whichWindow;
- short partCode;
-
- partCode = FindWindow(event->where, &whichWindow);
-
- switch (partCode)
- {
- case inDesk:
- break;
- case inMenuBar:
- AdjustMenuItems();
- HandleMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow:
- SystemClick(event, whichWindow);
- break;
- case inContent:
- break;
- case inDrag:
- DragWindow(whichWindow, event->where, &qd.screenBits.bounds);
- break;
- case inGrow:
- break;
- case inGoAway:
- if (whichWindow == (GrafPort *)gWindowP &&
- TrackGoAway((GrafPort *)gWindowP, event->where))
- gIsRunning = (ChoiceAlert(kWantToQuit) == TRUE ? FALSE : TRUE);
- break;
- case inZoomIn:
- case inZoomOut:
- break;
- default:
- break;
- }
- }
-
-
- void HandleKeyEvent(char key,short modifiers)
- {
- if ((modifiers & cmdKey) != 0)
- {
- AdjustMenuItems();
- HandleMenuCommand(MenuKey(key));
- }
- else // Secret codes! Cool!
- {
- MainLoopCodeCheck(key);
- }
- }
-
-
- void HandleUpdateEvent(WindowPtr updateWindowP)
- {
- if (updateWindowP == (WindowPtr)gWindowP)
- {
- SetPort(updateWindowP);
- BeginUpdate(updateWindowP);
-
- RefreshMainWindow();
-
- EndUpdate(updateWindowP);
- }
- }
-
- void RefreshMainWindow(void)
- {
- PicHandle BackGroundPict;
-
- BackGroundPict = GetPicture(kBackGroundPICTResID);
- if(BackGroundPict == nil)
- CantFindResource();
- HLock((Handle)BackGroundPict);
- DrawPicture(BackGroundPict, &gWindowP->portRect);
- HUnlock((Handle)BackGroundPict);
- ReleaseResource((Handle)BackGroundPict);
- }
-
-
- void HandleNullEvent(void)
- {
- return;
- }
-
-
- void HandleMenuCommand(long menuItemIdentifier)
- {
- short menuIdent = HiWord(menuItemIdentifier);
- short menuItem = LoWord(menuItemIdentifier);
-
- switch (menuIdent)
- {
- case kAppleMenuID:
- HandleAppleMenuCommand(menuItem);
- break;
- case kFileMenuID:
- HandleFileMenuCommand(menuItem);
- break;
- case kCombatMenuID:
- HandleCombatMenuCommand(menuItem);
- break;
- case kP1ControlMenuID:
- HandleP1ControlMenuCommand(menuItem);
- break;
- case kP2ControlMenuID:
- HandleP2ControlMenuCommand(menuItem);
- break;
- case kAdjustSpeedMenuID:
- HandleAdjustSpeedMenuCommand(menuItem);
- break;
- case kHiddenMenuID:
- HandleHiddenMenuCommand(menuItem);
- break;
- default:
- break;
- }
- HiliteMenu(0);
- }
-
-
- void HandleAppleMenuCommand(short menuItem)
- {
- Str255 deskAccName;
-
- switch (menuItem)
- {
- case kAboutItem:
- Ceremonies();
- break;
- case kInstructionsItem:
- Helper(kInstructionsPICTResID);
- break;
- case kHintsItem :
- Helper(kHintsPICTResID);
- break;
- case kMoreItem:
- Helper(kMorePICTResID);
- break;
- default:
- GetItem(GetMHandle(kAppleMenuID), menuItem, deskAccName);
- OpenDeskAcc(deskAccName);
- break;
- }
- }
-
-
- void HandleFileMenuCommand(short menuItem)
- {
- QNodePtr gHeadPtr=NULL, gTailPtr=NULL;
- KNodePtr ggHeadPtr=NULL, ggTailPtr=NULL;
- OSErr err;
- SpriteFileRec tournamentPlayer;
- CombatZoneFileRec tournamentZone;
- Str255 oldWTitle = "\p";
- Boolean hitOK = TRUE, player1Victorious;
-
- switch (menuItem)
- {
- case kManoAManoItem:
- DoMessage(kSelectPlayer1);
- gFileLoaded[kPlayer1Sprite] = GetMySpriteFile(&gPlayer1File);
- if(gFileLoaded[kPlayer1Sprite])
- {
- DoMessage(kSelectPlayer2);
- gFileLoaded[kPlayer2Sprite] = GetMySpriteFile(&gPlayer2File);
- }
- if(gFileLoaded[kPlayer2Sprite])
- {
- DoMessage(kSelectCombatZone);
- gFileLoaded[kArena] = GetMyArenaFile(&gCombatZoneFile);
- }
- if(gFileLoaded[kArena])
- {
- FillRect(&gWindowP->portRect, &qd.black);
- GetWTitle((WindowPtr)gWindowP, oldWTitle);
- SetWTitle((WindowPtr)gWindowP, gCombatZoneFile.sfFile.name);
- err = CombatCommand(&player1Victorious);
- if(err == noErr)
- {
- SetWTitle((WindowPtr)gWindowP, oldWTitle);
- gFileLoaded[kPlayer1Sprite] = FALSE;
- gFileLoaded[kPlayer2Sprite] = FALSE;
- gFileLoaded[kArena] = FALSE;
- }
- if(gSpeech && !gSoundOff)
- {
- switch(player1Victorious)
- {
- case TRUE:
- err = SpeakString("\pPlayer 1 Wins!");
- while(SpeechBusy())
- ;
- break;
- case FALSE:
- err = SpeakString("\pPlayer 2 Wins!");
- while(SpeechBusy())
- ;
- break;
- }
- }
- }
- RefreshMainWindow();
- break;
- case kTournamentItem:
- DoMessage(kFeatureNotAvailable);
- return; // get rid of this when computer control is fixed up.
- break;
- case kQuitItem:
- gIsRunning = (ChoiceAlert(kWantToQuit) == TRUE ? FALSE : TRUE);
- break;
- }
- }
-
-
- void HandleCombatMenuCommand(short menuItem)
- {
- OSErr err = noErr;
- Boolean player1Victorious;
- Str255 oldWTitle = "\p";
- long gestaltResult;
-
- switch(menuItem)
- {
- case kSpeechOnOffItem:
- if(gSpeech)
- {
- gSpeech = FALSE;
- DoMessage(kSpeechOff);
- }
- else
- {
- // Check for Speech Manager
- if(Gestalt( gestaltSpeechAttr, &gestaltResult ) == noErr)
- {
- if(BitTst(&gestaltResult, 31 - gestaltSpeechMgrPresent))
- {
- gSpeech = TRUE;
- DoMessage(kSpeechOn);
- }
- else
- gSpeech = FALSE;
- }
- }
- break;
- case kQuickTimeOnOffItem:
- if(gQT)
- {
- gQT = FALSE;
- DoMessage(kQTOff);
- }
- else
- {
- // Check for QuickTime™
- err = Gestalt( gestaltQuickTime, &gestaltResult );
- if (err == noErr)
- {
- err = EnterMovies();
- if (err == noErr)
- {
- gQT = TRUE;
- DoMessage(kQTOn);
- }
- }
- }
- break;
- default:
- break;
- }
- }
-
-
- void HandleP1ControlMenuCommand(short menuItem)
- {
- switch (menuItem)
- {
- case kHumanControlItem:
- gPlayer1Controller = kPlayer1Sprite;
- break;
- case kComputerControlItem:
- //gPlayer1Controller = kComputer1Sprite;
- DoMessage(kFeatureNotAvailable);
- break;
- }
- }
-
- void HandleP2ControlMenuCommand(short menuItem)
- {
- switch (menuItem)
- {
- case kHumanControlItem:
- gPlayer2Controller = kPlayer2Sprite;
- break;
- case kComputerControlItem:
- //gPlayer2Controller = kComputer2Sprite;
- DoMessage(kFeatureNotAvailable);
- break;
- }
- }
-
- void HandleAdjustSpeedMenuCommand(short menuItem)
- {
- gFrameAdvanceTime = (menuItem-1);
- }
-
- void HandleHiddenMenuCommand(short menuItem)
- {
- OSErr myErr;
-
- switch(menuItem)
- {
- case kThisIsHiddenMenuItem:
- if(gSpeech && !gSoundOff)
- {
- myErr = SpeakString("\pSurprise");
- while(SpeechBusy())
- ;
- }
- break;
- case kSoundOffItem:
- gSoundMax = FALSE;
- gSoundMegaMax = FALSE;
- gSoundOff = TRUE;
- break;
- case kMaxSoundItem:
- gSoundOff = FALSE;
- gSoundMegaMax = FALSE;
- gSoundMax = TRUE;
- break;
- case kMegaMaxSoundItem:
- gSoundOff = FALSE;
- gSoundMax = FALSE;
- gSoundMegaMax = TRUE;
- case kNormalSoundItem:
- gSoundOff = FALSE;
- gSoundMax = FALSE;
- gSoundMegaMax = FALSE;
- break;
- }
- }
-
- void AdjustMenuItems(void)
- {
- MenuHandle tempMenuH;
- short numItems, i;
-
- // adjust the Speed menu
- tempMenuH = GetMHandle(kAdjustSpeedMenuID);
- numItems = CountMItems(tempMenuH);
- for(i=1; i<=numItems; i++)
- CheckItem(tempMenuH, i, FALSE);
- CheckItem(tempMenuH, (gFrameAdvanceTime+1), TRUE);
-
- // Adjust sprite control menus
- // Player 1
- tempMenuH = GetMHandle(kP1ControlMenuID);
- numItems = CountMItems(tempMenuH);
- for(i=1; i<=numItems; i++)
- CheckItem(tempMenuH, i, FALSE);
- switch(gPlayer1Controller)
- {
- case kPlayer1Sprite:
- CheckItem(tempMenuH, 1, TRUE);
- break;
- case kComputer1Sprite:
- CheckItem(tempMenuH, 2, TRUE);
- break;
- default:
- break;
- }
- // Player 2
- tempMenuH = GetMHandle(kP2ControlMenuID);
- numItems = CountMItems(tempMenuH);
- for(i=1; i<=numItems; i++)
- CheckItem(tempMenuH, i, FALSE);
- switch(gPlayer2Controller)
- {
- case kPlayer2Sprite:
- CheckItem(tempMenuH, 1, TRUE);
- break;
- case kComputer2Sprite:
- CheckItem(tempMenuH, 2, TRUE);
- break;
- default:
- break;
- }
- }
-
- void enqueue(QNodePtr *headPtr, QNodePtr *tailPtr, QData value)
- {
- QNodePtr newPtr;
-
- newPtr = (QNodePtr)NewPtr(sizeof(QNode));
- if(newPtr != NULL)
- {
- newPtr->data = value;
- newPtr->nextPtr = NULL;
- if(isEmpty(*headPtr))
- *headPtr = newPtr;
- else
- (*tailPtr)->nextPtr = newPtr;
- *tailPtr = newPtr;
- }
- else
- DoError(kGeneralMemoryError, TRUE);
- }
-
- QData dequeue(QNodePtr *headPtr, QNodePtr *tailPtr)
- {
- QData value;
- QNodePtr tempPtr;
-
- value = (*headPtr)->data;
- tempPtr = *headPtr;
- *headPtr = (*headPtr)->nextPtr;
- if(*headPtr == NULL)
- *tailPtr = NULL;
- DisposePtr((Ptr)tempPtr);
- return value;
- }
-
- Boolean isEmpty(QNodePtr headPtr)
- {
- return headPtr == NULL;
- }
-
- void Kenqueue(KNodePtr *headPtr, KNodePtr *tailPtr, KData value)
- {
- KNodePtr newPtr;
-
- newPtr = (KNodePtr)NewPtr(sizeof(QNode));
- if(newPtr != NULL)
- {
- newPtr->data = value;
- newPtr->nextPtr = NULL;
- if(KisEmpty(*headPtr))
- *headPtr = newPtr;
- else
- (*tailPtr)->nextPtr = newPtr;
- *tailPtr = newPtr;
- }
- else
- DoError(kGeneralMemoryError, TRUE);
- }
-
- KData Kdequeue(KNodePtr *headPtr, KNodePtr *tailPtr)
- {
- KData value;
- KNodePtr tempPtr;
-
- value = (*headPtr)->data;
- tempPtr = *headPtr;
- *headPtr = (*headPtr)->nextPtr;
- if(*headPtr == NULL)
- *tailPtr = NULL;
- DisposePtr((Ptr)tempPtr);
- return value;
- }
-
- Boolean KisEmpty(KNodePtr headPtr)
- {
- return headPtr == NULL;
- }
-
-
- pascal OSErr HandleOpenApp(
- AppleEvent srcAppleEvent,
- AppleEvent replyAppleEvent,
- long refCon)
- {
- #if MPW
- #pragma unused(srcAppleEvent,replyAppleEvent,refCon)
- #endif
-
- return noErr;
- }
-
-
- pascal OSErr HandleOpenDoc(
- AppleEvent srcAppleEvent,
- AppleEvent replyAppleEvent,
- long refCon)
- {
- #if MPW
- #pragma unused(srcAppleEvent,replyAppleEvent,refCon)
- #endif
- return errAEEventNotHandled;
- }
-
-
- pascal OSErr HandlePrintDoc(
- AppleEvent srcAppleEvent,
- AppleEvent replyAppleEvent,
- long refCon)
- {
- #if MPW
- #pragma unused(srcAppleEvent,replyAppleEvent,refCon)
- #endif
- return errAEEventNotHandled;
- }
-
-
- pascal OSErr HandleQuit(
- AppleEvent srcAppleEvent,
- AppleEvent replyAppleEvent,
- long refCon)
- {
- #if MPW
- #pragma unused(srcAppleEvent,replyAppleEvent,refCon)
- #endif
- gIsRunning = false;
-
- return noErr;
- }
-
- short NumToolboxTraps(void)
- {
- return (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
- ? 0x0200 : 0x0400;
- }
-
-
- TrapType GetTrapType(short trap)
- {
- #define TrapMask 0x0800
-
- return ((trap & TrapMask) != 0) ? ToolTrap : OSTrap;
- }
-
-
- Boolean TrapAvail(short trap)
- {
- TrapType tType;
-
- tType = GetTrapType(trap);
- if (tType == ToolTrap)
- trap = trap & 0x07FF;
- if (trap >= NumToolboxTraps())
- trap = _Unimplemented;
- return NGetTrapAddress(trap, tType) !=
- NGetTrapAddress(_Unimplemented, ToolTrap);
- }
-
-
- Boolean HasWaitNextEvent(void)
- {
- return TrapAvail(_WaitNextEvent);
- }
-
- Boolean MacsBugInstalled(void)
- {
- /*
- How to tell if MacsBug is Installed
- This is a small snippet of code that can be used to to detect if
- macsbug is installed or not. NOTE: This code is intended to only work with
- version 6.2 of macsbug. You should refer to your Low Level Debugger's manual
- for more information on how they install themselves.
-
- This code is based on information obtained from the MacsBug Reference.
- The basic assumptions are that macsbug will install itself in the following
- manner:
-
- If you are running in 24 bit mode, then the high -order byte of MacJmp is a flags
- byte that contains the following information:
-
- Bit Meaning
- --- --------------------------------------
- 7 - Set if debugger is running
- 6 - Set if debugger can handle system errors
- 5 - Set if debugger is installed
- 4 - Set if debugger can support discipline utility
-
- The lower 3 bytes are used to store the address of the debugger's entry point.
-
- If you are running in 32-bit mode, the flags byte is moved to address 0xBFF and
- the long word at MacJmp becomes a full 32-bit address that points to the
- debugger's entry point..
-
- ADDENDUM: The above information seems to be incorrect in the reference
- manual. I have found through testing etc. that in both modes, the Flag Byte
- appears at location 0xBFF. The code reflects these findings.
-
- */
- Ptr FlagByte = (Ptr)0xBFF; // This is used only if running in 32 bit mode
-
- return (*FlagByte & 0x20/* Used to detect if bit 5 is set */);
-
- }
-
- /*
- If your program currently checks Gestalt to see if virtual memory is present,
- you will need to add a few lines of code to your program to determine if the result
- of the gestaltVMPresent means that Virtual Memory or RAM Doubler is present.
- The following C code contains two functions. The first, VMActive, checks to see if
- virtual memory is present. You probably already have similar code in your application,
- but we include the sample here for consistency and completeness. The second function,
- WhichVMIsInstalled, checks to see if RAM Doubler is present.
- */
- /* get some declarations out of the way */
- /* kNoVM = no virtual memory present */
- /* kSystem7 = System 7 virtual memory manager */
- /* kRAMDoubler = RAM Doubler is using VM hook */
- enum {
- kNoVM = 1,
- kSystem7,
- kRAMDoubler
- };
-
- void RDQTConflictCheck(void)
- {
- Boolean ramDoublerOn;
- short itemHit, hitOK=1;
-
- ramDoublerOn = (WhichVMIsInstalled() == kRAMDoubler);
- if(ramDoublerOn)
- {
- // Nevermind this - seems to work OK now!
- //itemHit = CautionAlert(kRDQTCautionAlertID, nil);
- //if(itemHit == hitOK)
- //gQT = FALSE;
- }
- }
-
- /* TYPICAL VIRTUAL MEMORY CHECK */
- /* VMActive returns True if virtual memory present */
- Boolean VMActive(void)
- {
- long response;
-
- return (GetOSTrapAddress(_Gestalt) != GetToolTrapAddress(_Unimplemented)
- && Gestalt(gestaltVMAttr, &response) == noErr
- && (response & (1<<gestaltVMPresent)));
- }
-
- /* ————————————————————————— */
- /* RAM DOUBLER CHECK */
- /* WhichVMIsInstalled tells you what kind of memory you’re dealing with:*/
- /* kNoVM = no virtual memory present */
- /* kSystem7 = System 7 virtual memory manager */
- /* kRAMDoubler = RAM Doubler is using VM hook */
- short WhichVMIsInstalled(void)
- {
- long vmSignature;
- if (!VMActive())
- {
- return kNoVM;
- }
- else
- {
- if(Gestalt('vmem', &vmSignature) == noErr && vmSignature == 'RaM2')
- {
- return kRAMDoubler;
- }
- else
- {
- return kSystem7;
- }
- }
- }
-